package com.es.www.kyl.util;

import cn.hutool.crypto.symmetric.SymmetricAlgorithm;
import cn.hutool.crypto.symmetric.SymmetricCrypto;
import cn.hutool.setting.dialect.Props;

import java.util.Base64;

/**
 * @Author by michangtao
 * @Date 2023/3/16 9:27
 * @Description
 */
public class AesUtils {

    /**
     * AES
     */
    private static final SymmetricCrypto aes;


    static {
        String path = "application-%s.properties";
        Props props = new Props(String.format(path, SpringContainerHolder.getActiveProfile()));
        String key = props.getProperty("token.aes.key");
        aes = new SymmetricCrypto(SymmetricAlgorithm.AES, Base64.getDecoder().decode(key));
    }

    /**
     * 加密
     * @param content
     * @return
     */
    public static String encrypt(String content){
        //DigestUtils.md5Hex
        return aes.encryptHex(content);
    }

    /**
     * 解密
     * @param content
     * @return
     */
    public static String decrypt(String content){
        return aes.decryptStr(content);
    }



    public static void main(String[] args) {
        String token = "1234_567";
        System.out.println(AesUtils.encrypt(token));
        System.out.println(AesUtils.decrypt("84bd086d79b957c585acaeeee2a70b0f1f506d445376ad47d811c4ad1457f5bc6ed01aa622e95802ebeb55006105b8b6"));
    }
}
